package br.edu.sistemaacademico;

import java.text.ParseException;

import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.Document;

import br.edu.sistemaacademico.Decorator.ConcretDecorator;
import br.edu.sistemaacademico.Memento.Memento;
import br.edu.sistemaacademico.adapter.IMenuCadastro;
import br.edu.sistemaacademico.observer.Observavel;
import br.edu.sistemaacademico.observer.Observer;
import br.edu.sistemaacademico.observer.ValidaEspecial;
import br.edu.sistemaacademico.pojo.Aluno;
import br.edu.sistemaacademico.util.Validar;
import client.ClientCommand;

public class frmAtualizaAluno extends IMenuCadastro {

	String causa = null;
    Aluno aluno;
    ConcretDecorator cc = null;
    br.edu.sistemaacademico.util.ValidaData dateVal = new br.edu.sistemaacademico.util.ValidaData();
    Validar cpfVal = new Validar();
	Memento n ;
    public frmAtualizaAluno(Aluno a) {
            this.aluno = a;
            n = aluno.save();
            execute();
    }

        @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLNome = new javax.swing.JLabel();
        jTNome = new javax.swing.JTextField();
        jTEndereco = new javax.swing.JTextField();
        jLEndereco = new javax.swing.JLabel();
        jLCidade = new javax.swing.JLabel();
        jTCPF = new javax.swing.JTextField();
        jTsexo = new javax.swing.JTextField();
        jLBairro = new javax.swing.JLabel();
        jLTelefone = new javax.swing.JLabel();
        jTTelefone = new javax.swing.JTextField();
        jBCancelar = new javax.swing.JButton();
        jBCadastrar = new javax.swing.JButton();
        infoTelefone = new javax.swing.JLabel();
        infoBairro = new javax.swing.JLabel();
        infoCidade = new javax.swing.JLabel();
        infoEndereco = new javax.swing.JLabel();
        infoNome = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        JtbRG = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jtbDtNasc = new javax.swing.JTextField();
        JtbLogin = new javax.swing.JTextField();
        JtbSenha = new javax.swing.JPasswordField();
        jLabel5 = new javax.swing.JLabel();
        JtbSenharetry = new javax.swing.JPasswordField();
        jLabel6 = new javax.swing.JLabel();
        JtbCoeficiente = new javax.swing.JTextField();
        infoBairro1 = new javax.swing.JLabel();
        infoBairro2 = new javax.swing.JLabel();
        infoBairro3 = new javax.swing.JLabel();
        infoBairro4 = new javax.swing.JLabel();
        infoBairro5 = new javax.swing.JLabel();
        infoBairro6 = new javax.swing.JLabel();

        setPreferredSize(new java.awt.Dimension(430, 194));

        jLNome.setText("Nome");

        jLEndereco.setText("Endereco");

        jLCidade.setText("CPF");

        jTsexo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTsexoActionPerformed(evt);
            }
        });

        jLBairro.setText("Sexo");

        jLTelefone.setText("Telefone");

        jTTelefone.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTTelefoneActionPerformed(evt);
            }
        });

        jBCancelar.setText("Cancelar");
        jBCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBCancelarActionPerformed(evt);
            }
        });

        jBCadastrar.setText("Atualizar");
        jBCadastrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBCadastrarActionPerformed(evt);
            }
        });

        infoTelefone.setFont(new java.awt.Font("Tahoma", 0, 9));
        infoTelefone.setText(" ");

        infoBairro.setFont(new java.awt.Font("Tahoma", 0, 9));
        infoBairro.setText("* Campo Obrigatorio");

        infoCidade.setFont(new java.awt.Font("Tahoma", 0, 9));
        infoCidade.setText("* Campo Obrigatorio");

        infoEndereco.setFont(new java.awt.Font("Tahoma", 0, 9));
        infoEndereco.setText("* Campo Obrigatorio");

        infoNome.setFont(new java.awt.Font("Tahoma", 0, 9));
        infoNome.setText("* Campo Obrigatorio");

        jLabel1.setText("RG");

        JtbRG.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JtbRGActionPerformed(evt);
            }
        });

        jLabel2.setText("Data Nascimento");

        jLabel3.setText("Login");

        jLabel4.setText("Senha");

        JtbSenha.setText("jPasswordField1");

        jLabel5.setText("Repita Senha");

        JtbSenharetry.setText("jPasswordField2");

        jLabel6.setText("Coeficiente");

        infoBairro1.setFont(new java.awt.Font("Tahoma", 0, 9));
        infoBairro1.setText("* Campo Obrigatorio");

        infoBairro2.setFont(new java.awt.Font("Tahoma", 0, 9));
        infoBairro2.setText("* Campo Obrigatorio");

        infoBairro3.setFont(new java.awt.Font("Tahoma", 0, 9));
        infoBairro3.setText("* Campo Obrigatorio");

        infoBairro4.setFont(new java.awt.Font("Tahoma", 0, 9));
        infoBairro4.setText("* Campo Obrigatorio");

        infoBairro5.setFont(new java.awt.Font("Tahoma", 0, 9));
        infoBairro5.setText("* Campo Obrigatorio");

        infoBairro6.setFont(new java.awt.Font("Tahoma", 0, 9));
        infoBairro6.setText("* Campo Obrigatorio");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLEndereco)
                            .addComponent(jLNome)
                            .addComponent(jLCidade)
                            .addComponent(jLabel1)
                            .addComponent(jLabel6)
                            .addComponent(jLTelefone))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jTTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap())
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(infoNome)
                                        .addContainerGap())
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(infoEndereco)
                                        .addContainerGap())
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(infoCidade)
                                        .addContainerGap())
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jTNome, javax.swing.GroupLayout.DEFAULT_SIZE, 379, Short.MAX_VALUE)
                                        .addGap(32, 32, 32))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jTEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, 303, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addContainerGap())
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(jTCPF, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                                                .addGap(38, 38, 38))
                                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(infoBairro)
                                                    .addComponent(JtbRG, javax.swing.GroupLayout.DEFAULT_SIZE, 226, Short.MAX_VALUE))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                                        .addComponent(jLBairro)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTsexo, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(100, 100, 100))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(infoBairro2)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(infoTelefone)))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(JtbCoeficiente, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addContainerGap())
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(infoBairro1)
                                    .addContainerGap()))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jBCadastrar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jBCancelar)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addGap(38, 38, 38)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(infoBairro6)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 86, Short.MAX_VALUE))
                                    .addComponent(JtbSenharetry, javax.swing.GroupLayout.DEFAULT_SIZE, 186, Short.MAX_VALUE)))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel4))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(infoBairro4)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                            .addComponent(jtbDtNasc, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 103, Short.MAX_VALUE))
                                        .addComponent(infoBairro3, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(infoBairro5, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(JtbSenha, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 186, Short.MAX_VALUE)
                                        .addComponent(JtbLogin, javax.swing.GroupLayout.Alignment.LEADING)))))
                        .addGap(190, 190, 190))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(infoNome)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE, false)
                            .addComponent(jLNome)
                            .addComponent(jTNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(2, 2, 2)
                        .addComponent(infoEndereco)
                        .addGap(2, 2, 2)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLEndereco)
                            .addComponent(jTEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(5, 5, 5)
                                .addComponent(infoCidade)
                                .addGap(3, 3, 3)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLCidade)
                                    .addComponent(jTCPF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(infoBairro)
                                .addGap(2, 2, 2)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel1)
                                    .addComponent(JtbRG, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLBairro)
                                    .addComponent(jTsexo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(6, 6, 6)
                        .addComponent(infoBairro1)
                        .addGap(2, 2, 2)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(JtbCoeficiente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addGap(10, 10, 10)
                        .addComponent(infoTelefone)
                        .addGap(2, 2, 2)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLTelefone)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(192, 192, 192)
                        .addComponent(infoBairro2)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(infoBairro3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtbDtNasc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(6, 6, 6)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(infoBairro4)
                        .addGap(2, 2, 2)
                        .addComponent(JtbLogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(infoBairro5)
                        .addGap(1, 1, 1)
                        .addComponent(JtbSenha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(7, 7, 7)
                        .addComponent(infoBairro6)
                        .addGap(1, 1, 1))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel4)
                        .addGap(18, 18, 18)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JtbSenharetry, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addGap(32, 32, 32)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBCadastrar))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jTsexoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTsexoActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_jTsexoActionPerformed

    private void jTTelefoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTTelefoneActionPerformed
       System.out.println("telefone");
}//GEN-LAST:event_jTTelefoneActionPerformed

    private void jBCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBCancelarActionPerformed
      	cc.setVisible(false);
		return;	
}//GEN-LAST:event_jBCancelarActionPerformed

    private void jBCadastrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBCadastrarActionPerformed
    	operacao();

}//GEN-LAST:event_jBCadastrarActionPerformed

    private void JtbRGActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JtbRGActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_JtbRGActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField JtbCoeficiente;
    private javax.swing.JTextField JtbLogin;
    private javax.swing.JTextField JtbRG;
    private javax.swing.JPasswordField JtbSenha;
    private javax.swing.JPasswordField JtbSenharetry;
    private javax.swing.JLabel infoBairro;
    private javax.swing.JLabel infoBairro1;
    private javax.swing.JLabel infoBairro2;
    private javax.swing.JLabel infoBairro3;
    private javax.swing.JLabel infoBairro4;
    private javax.swing.JLabel infoBairro5;
    private javax.swing.JLabel infoBairro6;
    private javax.swing.JLabel infoCidade;
    private javax.swing.JLabel infoEndereco;
    private javax.swing.JLabel infoNome;
    private javax.swing.JLabel infoTelefone;
    private javax.swing.JButton jBCadastrar;
    private javax.swing.JButton jBCancelar;
    private javax.swing.JLabel jLBairro;
    private javax.swing.JLabel jLCidade;
    private javax.swing.JLabel jLEndereco;
    private javax.swing.JLabel jLNome;
    private javax.swing.JLabel jLTelefone;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JTextField jTCPF;
    private javax.swing.JTextField jTEndereco;
    private javax.swing.JTextField jTNome;
    private javax.swing.JTextField jTTelefone;
    private javax.swing.JTextField jTsexo;
    private javax.swing.JTextField jtbDtNasc;
    // End of variables declaration//GEN-END:variables
    
    private Observavel docTelefone = new Observavel();
    private Observavel docNome = new Observavel();
    private Observavel docBairro = new Observavel();
    private Observavel docEndereco = new Observavel();
    private Observavel docCidade = new Observavel();


    public void execute() {
         initComponents();
         populaFields(aluno);
         if (cc==null)
                cc = new ConcretDecorator(this);
          

          
          initObserver();
          campoObrigatorio();
          //aluno = (Aluno) alunoDao.getObject("codigo = "+aluno.getId(),"*" , "");
          //populaFields(aluno);
          cc.setVisible(true);
    }

    public void initObserver(){
        Observer val = new ValidaEspecial();
        docTelefone.setDocument(jTTelefone.getDocument());
          docNome.setDocument(jTNome.getDocument());
          docBairro.setDocument(jTsexo.getDocument());
          docEndereco.setDocument(jTEndereco.getDocument());
          docCidade.setDocument(jTCPF.getDocument());

          docTelefone.addObserver(val);
          docNome.addObserver(val);
          docBairro.addObserver(val);
          docEndereco.addObserver(val);
          docCidade.addObserver(val);


          jTTelefone.getDocument().addDocumentListener(listener);
          jTNome.getDocument().addDocumentListener(listener);
          jTsexo.getDocument().addDocumentListener(listener);
          jTEndereco.getDocument().addDocumentListener(listener);
          jTCPF.getDocument().addDocumentListener(listener);
    }

    public void setTtelefone(Observavel observavel){
        observavel.setDocument(jTTelefone.getDocument());
        observavel.setChanged();
        observavel.notifyObservers();
        jTTelefone.setDocument(observavel.getDocument());

    }
        public void setTNome(Observavel observavel){
        observavel.setDocument(jTNome.getDocument());
        observavel.setChanged();
        observavel.notifyObservers();
        jTNome.setDocument(observavel.getDocument());
    }
        public void setTBairro(Observavel observavel){
        observavel.setDocument(jTsexo.getDocument());
        observavel.setChanged();
        observavel.notifyObservers();
        jTsexo.setDocument(observavel.getDocument());
    }
        public void setTEndereco(Observavel observavel){
        observavel.setDocument(jTEndereco.getDocument());
        observavel.setChanged();
        observavel.notifyObservers();
        jTEndereco.setDocument(observavel.getDocument());
    }
        public void setTCidade(Observavel observavel){
        observavel.setDocument(jTCPF.getDocument());
        observavel.setChanged();
        observavel.notifyObservers();
        jTCPF.setDocument(observavel.getDocument());
    }

    public void getEventDocument(Document doc){
        if(doc.equals(docTelefone.getDocument()))
                setTtelefone(docTelefone);
        else if(doc.equals(docNome.getDocument()))
                setTNome(docNome);
        else if(doc.equals(docBairro.getDocument()))
                setTBairro(docBairro);
        else if(doc.equals(docEndereco.getDocument()))
                setTEndereco(docEndereco);
        else if(doc.equals(docCidade.getDocument()))
                setTCidade(docCidade);
    }

    public void campoObrigatorio(){
        infoNome.setText("* Campo Obrigatorio");
        infoEndereco.setText("* Campo Obrigatorio");
        infoCidade.setText("* Campo Obrigatorio");
        infoBairro.setText("* Campo Obrigatorio");
    }
    
    DocumentListener listener = new DocumentListener() {

            public void insertUpdate(DocumentEvent e) {
               getEventDocument(e.getDocument());
            }

            public void removeUpdate(DocumentEvent e) {
                getEventDocument(e.getDocument());
            }

            public void changedUpdate(DocumentEvent e) {
                 getEventDocument(e.getDocument());
            }

        };

        public void populaAluno(Aluno o){
        o.setNome(jTNome.getText());
        o.setEndereco(jTEndereco.getText());
        o.setCpf(jTCPF.getText());
        o.setTelefone(jTTelefone.getText());
        o.setSexo(jTsexo.getText().charAt(0));
        o.setRg(JtbRG.getText());
        o.setNascimento(jtbDtNasc.getText());
        o.setLogin(JtbLogin.getText());
        if(JtbSenha.getText().equals(JtbSenharetry.getText()))
        o.setSenha(JtbSenha.getText());
        o.setAnoIngresso(2010);
        o.setCoeficiente(Float.parseFloat(JtbCoeficiente.getText()));
    }
    public void populaFields(Aluno o){
        jTNome.setText(o.getNome().toString());
        jTEndereco.setText(o.getEndereco());
        jTCPF.setText(o.getCpf());
        jTTelefone.setText(o.getTelefone());
        jTsexo.setText(o.getSexo().toString());
        JtbRG.setText(o.getRg());
        jtbDtNasc.setText(o.getNascimento());
        JtbCoeficiente.setText(String.valueOf(o.getCoeficiente()));
        JtbLogin.setText(o.getLogin());
        JtbSenha.setText(o.getSenha());
        JtbSenharetry.setText(o.getSenha());
    }
    public void limpaFields(){
        jTNome.setText("");
        jTEndereco.setText("");
        jTCPF.setText("");
        jTTelefone.setText("");
        jTsexo.setText("");
        JtbRG.setText("");
        jtbDtNasc.setText("");
        JtbLogin.setText("");
        JtbSenha.setText("");
        JtbSenharetry.setText("");
    }

    
	@Override
	public void menuExemplo(JMenuItem item) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void menuFechar(JMenuItem item) {
		cc.dispose();		
	}

	@Override
	public void menuLimpa(JMenuItem item) {
		limpaFields();		
	}

	@Override
	public void menuManual(JMenuItem item) {
		// TODO Auto-generated method stub		
	}

	@Override
	public void menuMementor(JMenuItem item) {
		restore();
	}

	@Override
	public void menuOperacao(JMenuItem item) {
		item.setText("Cadastrar Aluno");
		operacao();
	}

	@Override
	public void menuSobre(JMenuItem item) {
		// TODO Auto-generated method stub
		
	}
	
	public void operacao(){
		if(verefica()==true){
		populaAluno(aluno);
        if(ClientCommand.alterar("AlunoService",aluno)==false)        	
        	JOptionPane.showMessageDialog(null, "Nao foi possivel cadastrar o aluno");
        else{
        JOptionPane.showMessageDialog(null, "Aluno cadastrado com sucesso");
        //limpaFields();
        //n = aluno.save();
        }}else
        	JOptionPane.showMessageDialog(null, "Campos invalidos: "+causa);
	}
	public boolean verefica(){
		if(jTNome.getText().length()<=6){		
			causa="Nome deve conter mais de 6 letras";
		return false;
		}if(jTEndereco.getText().length()<=6){	
			causa="Endereco deve conter mais de 6 letras";
			return false;
		}if(jTCPF.getText().length()<13){		
			causa="cpf invalido";
		return false;
		}if(JtbRG.getText().length()<11){
			System.out.println(JtbRG.getText().length());
			causa="rg invalido";
		return false;
	}if(JtbCoeficiente.getText().length()<1){		
			causa="coeficiente invalido";
			return false;
	}if(jTTelefone.getText().length()<13)	{	
			causa="telefone invalido";
	}		try {if(!dateVal.isDate(jtbDtNasc.getText())){	causa="data invalida"; return false;}} catch (ParseException e) {	e.printStackTrace();	}
	if(JtbLogin.getText().length()<6){		
		causa="login deve conter mais de 6 caracters";
		return false;
	}if(JtbSenha.getText().length()<8){		
		causa="senha  deve conter mais de 8 caracters";
		return false;
	}
		return true;
	}
	
	public void restore(){
		aluno.restore(n);
		populaFields(aluno);
	}
}
